<%@page import="weaver.conn.RecordSet"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="com.zlgs.cqyf.vote.ConnectionUtil"%>
<%@ page import="com.alibaba.fastjson.*" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.sql.ResultSet" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    JSONObject retObject = new JSONObject();
    retObject.put("code", 200);
    retObject.put("msg", "操作成功");
    try {
        // URL 参数
        Integer awardsId = Integer.parseInt(request.getParameter("awardsId"));
        Object isPortal =  request.getParameter("isPortal");
        Object searchKey =  request.getParameter("searchKey");
        
        JSONArray array = new JSONArray();
        if(awardsId != null){
            // 数据库查询 
            String sql = "select * from vote_awards_subname where is_del = 0  ";
            		if(null==isPortal){
            			 sql +=	" and status<>0";
            		} 
            		if(null!=searchKey && !"".equals(searchKey.toString())){
            			 sql += "and name like N'%"+searchKey+"%'";
            		}
            		 sql += "and awards_id="+awardsId;
            RecordSet set  = new RecordSet();
            set.execute(sql);
            while(set.next()){
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("id",set.getInt("id"));                       // 子奖项id
                jsonObject.put("name",set.getString("name"));                // 子奖项名称
                jsonObject.put("status",set.getString("status"));            // 子奖项状态
                array.add(jsonObject);
            }
        }
        retObject.put("data", array);
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
        PrintWriter printWriter = response.getWriter();
        printWriter.append(retObject.toJSONString());
        if (printWriter != null)  printWriter.close();
    }
%>
 